<%--
  Created by IntelliJ IDEA.
  User: Cc
  Date: 2020/12/30
  Time: 16:51
  To change this template use File | Settings | File Templates.
--%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" +
            request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script type="text/javascript" src="/static/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="departmentname" class="layui-form-label">
                <span class="x-red">*</span>部门名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="departmentname" name="departmentname"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>名称
            </div>
        </div>

        <div class="layui-form-item">
            <label for="duty" class="layui-form-label">
                职责
            </label>
            <div class="layui-input-inline">
                <input type="text" id="duty" name="duty"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button type="button" class="layui-btn" id="L_repass" onclick="addDepartment()">
                增加
            </button>
        </div>
    </form>
</div>
<%--添加--%>
<script type="text/javascript">
    function addDepartment() {
        var departmentName = $("#departmentname").val();
        var departmentDuty = $("#duty").val();
        if (((departmentName!='')&&(departmentDuty)!="")) {
            $.ajax({
                url: "../department/addDepartment",
                type: "post",
                dataType: "text",
                async:false,
                data: {
                    departmentName: departmentName,
                    departmentDuty: departmentDuty,
                },
                success: function (data) {
                    console.log(data);
                    // if (data.code==200){}
                    layer.alert("添加成功",{icon:6},function () {
                        // 获得frame索引
                        let index = parent.layer.getFrameIndex(window.name);
                         //刷新父页面
                        parent.location.reload();
                       //关闭当前frame
                        parent.layer.close(index);
                    })
                }
            })
        }else {
            alert("请输入完整信息")
        }
    }
</script>
</body>

</html>
